package com.mjlf.mr.speed;

import com.mjlf.mr.utils.DateFormat;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.text.ParseException;

/**
 * @ClassName: SpeedMap
 * @Author: majun
 * @CreateDate: 2018/12/18 11:19
 * @Version: 1.0
 * @Description: TODO
 */

public class SpeedMap extends Mapper<LongWritable, Text, Speed, Text> {

    //    1999-22-22 12:12:12 A-xxxx  1231.12
    DoubleWritable doubleWritable = new DoubleWritable();
    Text text = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String str = value.toString();
        String[] strs = str.split("\t");

        Speed speed = new Speed();
        speed.setTime(strs[0].split(" ")[0]);
        speed.setCarN(strs[1]);
        speed.setSpeedNum(Double.parseDouble(strs[2]));
        doubleWritable.set(speed.getSpeedNum());

        text.set(strs[0] + "-" + strs[1] + "-->" + strs[2]);
        context.write(speed, text);
    }
}
